﻿var table1;
var url;

$(function () {
    url = "/Role/GetRole"
    table1 = $().hiTable({
        tableId: "SearchResult",
        pageBarId: "PageBar1",
        DefaultSortTitle: "Id",
        DefaultSortOrder: "1",
        ajaxURL: url,
        columnsConfig: [
                { Title: 'RoleName' },
                { Title: 'Description' },
                { FnRender: function (item) {
                    var RoleId = "'" + item["Id"] + "'";
                    return '<img alt="角色修改" style=\"cursor:pointer\" title="角色修改" onclick="Edit(' + RoleId + ')"  src="../../Content/images/edit.png" />&nbsp;&nbsp;&nbsp;' +
                        '<img alt="删除" style=\"cursor:pointer\" title="删除 " onclick="Delete(' + RoleId + ')"  src="../../Content/images/delete.png" / />&nbsp;&nbsp;&nbsp;' +
                        '<img alt="人员设置" style=\"cursor:pointer\" title="人员设置" onclick="Setting(' + RoleId + ')"  src="../../Content/images/person.png" / /></td></tr>';
                }
                }
                ]
    });

    //PageLoad时，加载数据
    table1.loadData(parseInt($("#perPage").val()), 0);

    //改变每页显示条数
    $("#perPage").change(function () {
        table1.loadData(parseInt($(this).val()), 0);
    });
});
//搜索
function Search() {
    var Search = $.trim($("#TextSearch").val()); //搜索关键字 
    url = "/Role/GetRole?search=" + Search;

    table1 = $().hiTable({
        tableId: "SearchResult",
        pageBarId: "PageBar1",
        DefaultSortTitle: "Id",
        DefaultSortOrder: "1",
        ajaxURL: url,
        columnsConfig: [
                { Title: 'RoleName' },
                { Title: 'Description' },
                { FnRender: function (item) {
                    var RoleId = "'" + item["Id"] + "'";
                    return '<img alt="角色修改" style=\"cursor:pointer\" title="角色修改" onclick="Edit(' + RoleId + ')"  src="../../Content/images/edit.png" />&nbsp;&nbsp;&nbsp;' +
                        '<img alt="删除" style=\"cursor:pointer\" title="删除 " onclick="Delete(' + RoleId + ')"  src="../../Content/images/delete.png" / />&nbsp;&nbsp;&nbsp;' +
                        '<img alt="人员设置" style=\"cursor:pointer\" title="人员设置" onclick="Setting(' + RoleId + ')"  src="../../Content/images/person.png" / /></td></tr>';
                }
                }
                ]
    });
    //PageLoad时，加载数据
    table1.loadData(parseInt($("#perPage").val()), 0);
    //改变每页显示条数
    $("#perPage").change(function () {
        table1.loadData(parseInt($(this).val()), 0);
    });
}

//删除按钮方法
function Delete(roleId) {
    if (confirm(SureDelete)) {
        $.post('/Role/DeleteRole', {
            Id: roleId
        }, function (data) {
            if (data == "True") {
                alert(DeleteSuccess);
                //重新加载页面               
                table1.loadData(parseInt($("#perPage").val()), 0);
            }
        })
    }
}

//人员设置
function Setting(roleId) {
    url = "/Role/Setting?RoleId=" + roleId;
    window.location.href = url, { cache: false };
}
//角色修改按钮
function Edit(roleId) {
    var url = "/Role/Edit?Id=" + roleId;
    window.location.href = url;
}


//角色修改按钮
function AddRole() {
    var url = "/Role/Add";
    window.location.href = url;
}

